package pl.edu.agh.gt.ga.greedy;

import java.util.LinkedList;
import java.util.List;

import pl.edu.agh.gt.ga.Genotype;
import pl.edu.agh.gt.ga.Individual;
import pl.edu.agh.gt.ga.Initializer;
import pl.edu.agh.gt.ga.Parameters;
import pl.edu.agh.gt.util.BetterRandom;

public class InitializerImpl implements Initializer {


	@Override
	public List<Individual> initialize(Parameters params) {

		List<Individual> population = new LinkedList<Individual>();
		
		for( int i = 0; i < params.initialPopulationSize ; i++) {

			Genotype gens = createGenotype();
						
			//gens.setGene("resolution", 	(int)generateRandom(1,5) );
			gens.setGene("greedA", 			BetterRandom.nextFloat("ga",0,200) );
			//gens.setGene("greedB", 		BetterRandom.nextFloat("gb",0,100) );
			gens.setGene("maxLoss", 		BetterRandom.nextFloat("ml",-200,0) );
			gens.setGene("desiredEarn", 	BetterRandom.nextFloat("de",0,200) );
			gens.setGene("enteringValue", 	BetterRandom.nextFloat("ev",50,5000) );
			gens.setGene("lossTolerancy", 	BetterRandom.nextFloat("lt",0,200) );
			
			Individual ind = new Individual(gens);
			population.add(ind);
		}
		
		return population;
	}
	
	public static Genotype createGenotype () {
		Genotype gens = new Genotype();
		//gens.addGeneInt("resolution");
		gens.addGeneFloat("greedA");
		//gens.addGeneFloat("greedB");
		gens.addGeneFloat("maxLoss");
		gens.addGeneFloat("desiredEarn");
		gens.addGeneFloat("enteringValue");
		gens.addGeneFloat("lossTolerancy");
		return gens;
	}
}
